package xyz.jcat.generator.mybatis.convert;

import xyz.jcat.generator.mybatis.config.JavaType;

/**
 * Mysql数据表类型转换java类型的工具类
 *
 * @author yueyue
 * @Time 2017-05-16 17:36
 */
public class MysqlTypeConvert implements xyz.jcat.generator.mybatis.convert.ITypeConvert {

    public JavaType javaTypeConvert(String dbType) {
        dbType = dbType.toLowerCase();
        if (dbType.contains("char") || dbType.contains("text")) {
            return JavaType.STRING;
        } else if (dbType.contains("bigint")) {
            return JavaType.LONG;
        } else if (dbType.contains("int")) {
            return JavaType.INTEGER;
        } else if (dbType.contains("date") || dbType.contains("time") || dbType.contains("year")) {
            return JavaType.DATE;
        } else if (dbType.contains("bit")) {
            return JavaType.BOOLEAN;
        } else if (dbType.contains("decimal")) {
            return JavaType.BIG_DECIMAL;
        } else if (dbType.contains("blob")) {
            return JavaType.BYTE_ARRAY;
        } else if (dbType.contains("float")) {
            return JavaType.FLOAT;
        } else if (dbType.contains("double")) {
            return JavaType.DOUBLE;
        } else if (dbType.contains("json") || dbType.contains("enum")) {
            return JavaType.STRING;
        }
        return JavaType.STRING;
    }
}
